package com.hlhj.funlike_business.data;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

public class SPUser {
    public static SPUser sp;
    private Context context;
    private SharedPreferences sharedPreferences;
    private static final String sp_configer = "user_info";

    public static final String TOKEN = "token";
    public static final String SHOPNAME = "shop_name";
    public static final String SHOPADVERT = "shop_advert";
    public static final String SHOPTEL= "shop_tel";
    public static final String SHOPCRICLE = "shop_cricle";
    public static final String SHOPTIME = "shop_time";
    public static final String SHOPTAKETYPE = "shop_taketype";
    public static final String SHOPSTATUS= "shop_status";
    public static final String SHOPIMG= "shop_img";



    public SPUser(Context context) {
        this.context = context;
        sharedPreferences=context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
    }

    public static SPUser getUser(Application context){
        if (sp == null){
            synchronized (SPUser.class){
                if (sp == null)
                    sp = new SPUser(context);
            }
        }
        return sp;
    }

    public SPUser setToken(String token){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        sharedPreferences.edit().putString(TOKEN,token).commit();
        return this;
    }

    public String getToken(){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        return sharedPreferences.getString(TOKEN,"");
    }

    public SPUser setShopName(String shopName){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        sharedPreferences.edit().putString(SHOPNAME,shopName).commit();
        return this;
    }

    public String getShopname(){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        return sharedPreferences.getString(SHOPNAME,"");
    }

    public SPUser setShopAdvert(String shopAdvert){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        sharedPreferences.edit().putString(SHOPADVERT,shopAdvert).commit();
        return this;
    }

    public String getShopAdvert(){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        return sharedPreferences.getString(SHOPADVERT,"");
    }

    public SPUser setShopTel(String shopTel){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        sharedPreferences.edit().putString(SHOPTEL,shopTel).commit();
        return this;
    }

    public String getShopTel(){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        return sharedPreferences.getString(SHOPTEL,"");
    }

    public SPUser setShopCricle(String shopCricle){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        sharedPreferences.edit().putString(SHOPCRICLE,shopCricle).commit();
        return this;
    }

    public String getShopCricle(){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        return sharedPreferences.getString(SHOPCRICLE,"");
    }

    public SPUser setShopTime(String shopTime){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        sharedPreferences.edit().putString(SHOPTIME,shopTime).commit();
        return this;
    }

    public String getShopTime(){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        return sharedPreferences.getString(SHOPTIME,"");
    }

    public SPUser setShopTakeType(String shopTakeType){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        sharedPreferences.edit().putString(SHOPTAKETYPE,shopTakeType).commit();
        return this;
    }

    public String getShopTakeType(){
        sharedPreferences = context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        return sharedPreferences.getString(SHOPTAKETYPE,"");
    }

    public SPUser setShopStatus(int type) {
        sharedPreferences=context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        sharedPreferences.edit().putInt(SHOPSTATUS,type).commit();
        return this;
    }

    public int getShopStatus(){
        sharedPreferences=context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        return sharedPreferences.getInt(SHOPSTATUS,1);
    }
    public SPUser setShopImg(String imgUrl) {
        sharedPreferences=context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        sharedPreferences.edit().putString(SHOPIMG,imgUrl).commit();
        return this;
    }

    public String getShopImg(){
        sharedPreferences=context.getSharedPreferences(sp_configer,Context.MODE_PRIVATE);
        return sharedPreferences.getString(SHOPIMG,"");
    }
}
